package com.lht.admin.service.impl;

import com.lht.admin.entity.AddressCodeToValueDto;
import com.lht.admin.service.AddressAreaService;
import com.lht.admin.service.AddressCityService;
import com.lht.admin.service.AddressProvinceService;
import com.lht.admin.service.AddressService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 地址信息业务层实现
 *
 * @author: Frank
 * @date: 2019/9/29 14:23
 * @version: V1.0
 */
@Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressProvinceService addressProvinceService;
    @Autowired
    private AddressCityService addressCityService;
    @Autowired
    private AddressAreaService addressAreaService;

    @Override
    public AddressCodeToValueDto customValueByCode(String provinceCode, String cityCode, String areaCode) {
        AddressCodeToValueDto addressCodeToValueDto = new AddressCodeToValueDto();
        addressCodeToValueDto.setProvinceCode(provinceCode);
        addressCodeToValueDto.setCityCode(cityCode);
        addressCodeToValueDto.setAreaCode(areaCode);
        if (StringUtils.isNotBlank(provinceCode)) {
            Map<String, String> provinceMap = addressProvinceService.getAllCodeMap();
            addressCodeToValueDto.setProvinceValue(provinceMap.get(provinceCode));
        }
        if (StringUtils.isNotBlank(cityCode)) {
            Map<String, String> cityMap = addressCityService.getAllCodeMap();
            addressCodeToValueDto.setCityValue(cityMap.get(cityCode));
        }
        if (StringUtils.isNotBlank(areaCode)) {
            Map<String, String> areaMap = addressAreaService.getAllCodeMap();
            addressCodeToValueDto.setAreaValue(areaMap.get(areaCode));
        }
        return addressCodeToValueDto;
    }

}
